package com.ssy.wireless.web.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ssy.wireless.entity.Enterprise;
import com.ssy.wireless.web.service.EnterpriseService;
import com.ssy.wireless.web.vo.req.EntQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by cofey on 16/11/20.
 */
@RestController
@RequestMapping("/ent")
public class EnterpriseController extends AbstractController {
    @Autowired
    private EnterpriseService enterpriseService;

    @GetMapping("/")
    public ModelAndView list() {
        return new ModelAndView("ent/list");
    }

    @PostMapping("/content")
    public ModelAndView content(
            @RequestParam(value = "pageIndex", defaultValue = "1", required = false) int pageIndex,
            @RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize,
            EntQueryVo vo
    ) {
        Assert.isTrue(pageSize < 200, "每页显示条数不能大于200");
        Page<Enterprise> page = PageHelper.offsetPage(pageIndex - 1, pageSize);
        enterpriseService.find(vo.queryParams());
        return new ModelAndView("ent/content", result(page));
    }
}
